package com.example.manager;

import com.example.entity.Dept;
import com.example.mapper.DeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class DeptManager {

    @Autowired
    private DeptManager2 deptManager2;
    @Autowired
    private DeptMapper deptMapper;

    @Transactional
    public void insertDept(Dept dept){
        try{
            deptManager2.insertDept(dept);
//            deptManager2.insertDept(dept," ");
            //insertDept(dept," ");
        }catch (Exception e){
            dept.setDname(dept.getDname()+"错误后设置");
        }finally {
            deptMapper.insert(dept);
            //System.out.println(10/0);
        }
    }


    /**
     * 如果只有一层事物，第一次循环回滚了，不影响后面的。
     */
    @Transactional
    public void insertDept(Dept dept,int str){
        deptMapper.insert(dept);
        System.out.println(10/str);
    }
}
